package com.ylr.blog.framework.manager;

import com.ylr.blog.common.constant.BlogConstant;
import com.ylr.blog.framework.service.BlogFlowService;
import lombok.AllArgsConstructor;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-06-05 10:38:16
 * className: BlogFlowManager
 * version: 1.0
 * description:
 */
@Service("blogFlowManager")
@AllArgsConstructor
public class BlogFlowManager {

    private static final Logger log = LoggerFactory.getLogger(BlogFlowManager.class);

    private final BlogFlowService blogFlowService;

    /**
     * 保存博客流水操作
     * @param blogId 博客主键
     * @param code   博客编号
     * @param status 状态
     * @param remark 备注
     */
    public void saveBlogFlow(Long blogId, String code, Integer status, String remark) {
        try (HintManager hintManager = HintManager.getInstance()) {
            // 设置分库分表的分片键
            hintManager.addDatabaseShardingValue(BlogConstant.BLOG_FLOW, code);
            hintManager.addTableShardingValue(BlogConstant.BLOG_FLOW, code);

            blogFlowService.saveBlogFlow(blogId, status, remark);
        }
    }
}
